// localStorage的二次封装

import config from "../config/index"

export default {
    getStorage() {
        return JSON.parse(window.localStorage.getItem(config.namespace) || "{}")
    },

    setItem(key, value) {
        let storage = this.getStorage();
        storage[key] = value;
        window.localStorage.setItem(config.namespace, JSON.stringify(storage));
    },

    getItem(key){
        let storage = this.getStorage();
        return storage[key];
    },

    clearItem(key){
        let storage = this.getStorage();
        delete storage[key];
        window.localStorage.setItem(config.namespace, JSON.stringify(storage));
    },

    clearAll(){
        // window.localStorage.clear();
        localStorage.removeItem(config.namespace);
    }
}